home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
129_01
/
210log.c
< prev
next >
Wrap
Text File
|
1985-03-09
|
18KB
|
615 lines
/************************************************************************/
/* log.c */
/* */
/* userlog code for Citadel bulletin board system */
/************************************************************************/
/************************************************************************/
/* history */
/* */
/* 84Dec28 HAW findPerson() moved from MSG.C to LOG.C. */
/* 84Dec12 HAW Fixed kill acct. bug so killed acct doesn't become login*/
/* 84Jun23 HAW&JLS Eliminating unused local variables using CRF. */
/* 84Jun19 JLS Fixed terminate so that Mail> doesn't screw up SYSOP. */
/* 84Apr04 HAW Started upgrade to BDS C 1.50a. */
/* 83Feb27 CrT Fixed login-in-Mail> bug. */
/* 83Feb26 CrT Limited # new messages for new users. */
/* 83Feb18 CrT Null pw problem fixed. */
/* 82Dec06 CrT 2.00 release. */
/* 82Nov03 CrT Began local history file & general V1.2 cleanup */
/************************************************************************/
#include <210ctdl.h>
/************************************************************************/
/* contents */
/* */
/* crypte() encrypts/decrypts data blocks */
/* findPerson() load log record for named person */
/* getLog() loads requested userlog record */
/* hash() hashes a string to an integer */
/* login() is menu-level routine to log caller in */
/* logInit() builds the RAM index to userlog.buf */
/* newPW() is menu-level routine to change a PW */
/* newUser() menu-level routine to log a new caller */
/* noteLog() enters a userlog record into RAM index */
/* putLog() stores a logBuffer into citadel.log */
/* PWSlot() returns userlog.buf slot password is in */
/* slideLTab() support routine for sorting logTab */
/* sortLog() sort userlog by time since last call */
/* storeLog() store data in log */
/* strCmpU() strcmp(), but ignoring case distinctions*/
/* terminate() menu-level routine to exit system */
/* zapLogFile() erases & re-initializes userlog.buf */
/************************************************************************/
/************************************************************************/
/* crypte() encrypts/decrypts data blocks */
/* */
/* This was at first using a full multiply/add pseudo-random sequence */
/* generator, but 8080s don't like to multiply. Slowed down I/O */
/* noticably. Rewrote for speed. */
/************************************************************************/
#define b fpc1
#define c fi1
#define s fi2
crypte(buf, len, seed)
char *buf;
unsigned len, seed;
{
seed = (seed + cryptSeed) & 0xFF;
b = buf;
c = len;
s = seed;
for (; c; c--) {
*b++ ^= s;
s = (s + CRYPTADD) & 0xFF;
}
}
/************************************************************************/
/* findPerson() loads log record for named person. */
/* RETURNS: ERROR if not found, else log record # */
/************************************************************************/
int findPerson(name, lBuf)
char *name;
struct logBuffer *lBuf;
{
int h, i, foundIt, logNo;
h = hash(name);
for (foundIt=i=0; i<MAXLOGTAB && !foundIt; i++) {
if (logTab[i].ltnmhash == h) {
getLog(lBuf, logNo = logTab[i].ltlogSlot);
if (strCmpU(name, lBuf->lbname) == SAMESTRING) {
foundIt = TRUE;
}
}
}
if (!foundIt) return ERROR;
else return logNo;
}
/************************************************************************/
/* getLog() loads requested log record into RAM buffer */
/************************************************************************/
getLog(lBuf, n)
struct logBuffer *lBuf;
int n;
{
if (lBuf == &logBuf) thisLog = n;
n *= SECSPERLOG;
seek(logfl, n, 0);
if (read(logfl, lBuf, SECSPERLOG) == -1) {
printf("?getLog-read fail");
}
crypte(lBuf, (SECSPERLOG*SECTSIZE), n); /* decode buffer */
}
/************************************************************************/
/* hash() hashes a string to an integer */
/************************************************************************/
int hash(str)
char *str;
{
char toUpper();
int h, i, shift;
for (h=shift=0; *str; shift=(shift+1)&7, str++) {
h ^= (i=toUpper(*str)) << shift;
}
return h;
}
/************************************************************************/
/* login() is the menu-level routine to log someone in */
/************************************************************************/
login(password)
char *password; /* TRUE if parameters follow */
{
char getYesNo();
int foundIt, ltentry;
foundIt = ((ltentry = PWSlot(password, /* load == */ TRUE)) != ERROR);
if (foundIt && *password) {
/* recite caller's name, etc: */
mPrintf(" %s\n", logBuf.lbname);
/* update userlog entries: */
loggedIn = TRUE;
setUp(TRUE);
showMessages(NEWoNLY, FALSE);
listRooms(/* doDull== */ !expert);
outFlag = OUTOK;
if (
(
logBuf.lbId[MAILSLOTS-1]
-
(logBuf.lbvisit[ logBuf.lbgen[MAILROOM] & CALLMASK ]+1)
< 0x8000
)
&&
logBuf.lbId[MAILSLOTS-1] - oldestLo < 0x8000
&&
thisRoom != MAILROOM
) {
mPrintf("\n * You have private mail in Mail> *\n ");
}
} else {
/* discourage password-guessing: */
if (strLen(password) > 1 && whichIO == MODEM) pause(2000);
if (!unlogLoginOk && whichIO == MODEM) {
mPrintf(" No record -- leave message to 'sysop' in Mail>\n ");
} else if (getYesNo(" No record: Enter as new user")) newUser();
}
}
/************************************************************************/
/* logInit() indexes userlog.buf */
/************************************************************************/
logInit()
{
int i;
int count;
count = 0;
/* clear logTab */
for (i=0; i<MAXLOGTAB; i++) logTab[i].ltnewest = ERROR;
/* load logTab: */
for (thisLog=0; thisLog<MAXLOGTAB; thisLog++) {
printf("log#%d", thisLog);
getLog(&logBuf, thisLog);
/* count valid entries: */
if (logBuf.lbvisit[0] != ERROR) {
count++;
printf(" %s", logBuf.lbname);
}
putChar('\n');
/* copy relevant info into index: */
logTab[thisLog].ltnewest = logBuf.lbvisit[0];
logTab[thisLog].ltlogSlot= thisLog;
logTab[thisLog].ltnmhash = hash(logBuf.lbname);
logTab[thisLog].ltpwhash = hash(logBuf.lbpw );
}
printf(" logInit--%d valid log entries\n", count);
sortLog();
}
/************************************************************************/
/* newPW() is menu-level routine to change one's password */
/* since some Citadel nodes run in public locations, we avoid */
/* displaying passwords on the console. */
/************************************************************************/
newPW()
{
char oldPw[NAMESIZE];
char pw[NAMESIZE];
char *s;
int goodPW;
/* save password so we can find current user again: */
if (!loggedIn) {
mPrintf("?Can't change pwd when not logged in!\n ");
return ;
}
strcpy(oldPw, logBuf.lbpw);
storeLog();
do {
echo = CALLER;
getNormStr(" new password", pw, NAMESIZE);
echo = BOTH;
/* check that PW isn't already claimed: */
goodPW = (PWSlot(pw, /* load == */ TRUE) == ERROR && strlen(pw) >= 2);
if (!goodPW) mPrintf("\n Poor password\n ");
} while (!goodPW && (haveCarrier || whichIO==CONSOLE));
doCR();
PWSlot(oldPw, /* load == */TRUE); /* reload old log entry */
pw[NAMESIZE-1] = 0x00; /* insure against loss of carrier: */
if (goodPW && strlen(pw) > 1) { /* accept new PW: */
strcpy(logBuf.lbpw, pw);
logTab[0].ltpwhash = hash(pw);
}
mPrintf("\n %s\n pw: ", logBuf.lbname);
echo = CALLER;
mPrintf("%s\n ", logBuf.lbpw);
echo = BOTH;
}
/************************************************************************/
/* newUser() prompts for name and password */
/***********************